package com.hyts.keygen.handler;

import com.hyts.keygen.config.KeyWorkProperties;

import java.util.Date;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.keygen.util
 * @author:Libo/Alex
 * @create-date:2019-05-26 08:09
 * @copyright:libo-hyts-github
 * @email:libo2dev@aliyun.com
 * @description:此类主要用于: key 时间戳 工具操作处理器
 */
public class KeyTimeHandler {


    public static Long generate(long offset){
        return System.currentTimeMillis() - offset;
    }

    public static Long generate(){
        return generate(KeyWorkProperties.DEFAULT_TIME_EPOCH_OFFSET);
    }

    public static Long generate(Date offset){
        return System.currentTimeMillis() - offset.getTime();
    }

    public static long generateNextMillis(long lastTimestamp) {
        long timestamp = generate();
        while (timestamp <= lastTimestamp) {
            timestamp = generate();
        }
        return timestamp;
    }

}
